#pragma once 

#include "ParticleEffect.h"
#include "ParticleSystem.h"

#include "Terrain.h"
#include "GameManager.h"

class ProjectileEffect : public ParticleEffect
{
public:
    ProjectileEffect(ParticleSystem* ps, glm::vec3 startPos, glm::vec3 speed)
        : ParticleEffect(ps), pos(startPos), speed(speed), lifeTime(0)
    {
        gm = GameManager::getInstance();
        //ps->addParticles(pos, speed, 20.0f, 128);
    }

    virtual void update(float dt)
    {
        lifeTime += dt;
        
        speed += glm::vec3(0.0f, -9.81f, 0.0f)*dt;
        pos += speed * dt;

        ps->addParticles(pos, 0.1f, glm::vec3(0), 0.05f, 2.0f, static_cast<unsigned int>(1000 * dt));

        float terrainHeight = gm->terrain->sample(glm::vec2(pos.x, pos.z));
        if ( pos.y <= terrainHeight )
        { // terrain impact 
            ps->addParticles(pos, 2.0f, glm::vec3(0.0f, 2.0f, 0.0f), 0.8f, 1.0f, 5000);
            dead = true;
        }
    }

private:
    float lifeTime;
    glm::vec3 pos;
    glm::vec3 speed;
    GameManager* gm;
};